﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using System.Web.UI;

namespace HuoTu.Common
{
    /// <summary>
    /// 系统日志类
    /// 修改者：罗国华
    /// 修改日期：2010.10.8
    /// </summary>
    public class SysLog
    {
        public SysLog() { }

        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="txt"></param>
        public static void WriteLog(string txt)
        {
            string path = SysString.ChangePath("/") + "/Log";
            DirectoryInfo d = new DirectoryInfo(path);
            if (!d.Exists) d.Create();
            string filePath = path + string.Format(@"/SysLog{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
            StreamWriter rw = new StreamWriter(filePath, true, System.Text.Encoding.Default);
            rw.WriteLine(string.Format(@"error {0}", DateTime.Now.ToString()));
            rw.WriteLine(txt);
            rw.Flush();
            rw.Close();
        }

        public static void Info(string txt)
        {
            string path = SysString.ChangePath("/") + "/Log";
            DirectoryInfo d = new DirectoryInfo(path);
            if (!d.Exists) d.Create();
            string filePath = path + string.Format(@"/SysLog{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
            StreamWriter rw = new StreamWriter(filePath, true, System.Text.Encoding.Default);
            rw.WriteLine(string.Format(@"{0}", DateTime.Now.ToString()));
            rw.WriteLine(txt);
            rw.Flush();
            rw.Close();
        }

        public static void Error(string txt)
        {
            string path = SysString.ChangePath("/") + "/Log";
            DirectoryInfo d = new DirectoryInfo(path);
            if (!d.Exists) d.Create();
            string filePath = path + string.Format(@"/SysLog{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
            StreamWriter rw = new StreamWriter(filePath, true, System.Text.Encoding.Default);
            rw.WriteLine(string.Format(@"error {0}", DateTime.Now.ToString()));
            rw.WriteLine(txt);
            rw.Flush();
            rw.Close();
        }

        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="path"></param>
        /// <param name="txt"></param>
        public static void WriteLog(string path, string txt)
        {
            DirectoryInfo d = new DirectoryInfo(path);
            if (!d.Exists) d.Create();
            string filePath = path + string.Format(@"/SysLog{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
            StreamWriter rw = new StreamWriter(filePath, true, System.Text.Encoding.Default);
            rw.WriteLine(string.Format(@"error {0}", DateTime.Now.ToString()));
            rw.WriteLine(txt);
            rw.Flush();
            rw.Close();
        }

        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="path"></param>
        /// <param name="txt"></param>
        /// <param name="logName"></param>
        public static void WriteLog(string path, string txt, string logName)
        {
            DirectoryInfo d = new DirectoryInfo(path);
            if (!d.Exists) d.Create();
            string filePath = path + string.Format(@"/{1}{0}.log"
                , DateTime.Now.ToString("yyyy-MM-dd"), logName);
            StreamWriter rw = new StreamWriter(filePath, true, System.Text.Encoding.Default);
            rw.WriteLine(string.Format(@"error {0}", DateTime.Now.ToString()));
            rw.WriteLine(txt);
            rw.Flush();
            rw.Close();
        }

    }
}